<template>
    <div>
        <el-form ref="form"  label-width="100px">
            <el-form-item label="投诉人">
                <span style="font-weight:bolder;font-size:30px;color:green">{{nowComplaints.name.name}}</span>
            </el-form-item>
            <el-form-item label="投诉对象">
                <span style="font-weight:bolder;font-size:30px;color:darkred">{{nowComplaints.cplTarget.username}}</span>
            </el-form-item>
            <el-form-item label="投诉内容">
                <span>{{nowComplaints.content}}</span>
            </el-form-item>
            <el-form-item label="选择扣分对象">
                <el-select v-model="result.state" @change="result.content=result.state=='投诉对象'?result.content=`扣分对象为--被投诉对象：${nowComplaints.cplTarget.username}，信用值扣：${result.point}分 备注：`:result.content=`扣分对象为--投诉人：${nowComplaints.name.name}，信用值扣：${result.point}分  备注：`">
                    <el-option value="投诉对象" >投诉对象：{{nowComplaints.cplTarget.username}}</el-option>
                    <el-option value="投诉人" >投诉人：{{nowComplaints.name.name}}</el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="选择扣分" >
                <el-select v-model="result.point" @change="result.content=result.state=='投诉对象'?result.content=`扣分对象为--投诉对象：${nowComplaints.cplTarget.username}，信用值扣：${result.point}分 备注：`:result.content=`扣分对象为--投诉人：${nowComplaints.name.name}，信用值扣：${result.point}分  备注：`">
                    <el-option value="0" >0</el-option>
                    <el-option value="5" >5</el-option>
                    <el-option value="10" >10</el-option>
                    <el-option value="15" >15</el-option>
                    <el-option value="20" >20</el-option>
                </el-select>
            </el-form-item>
              <el-form-item label="处理结果">
                <el-input type="textarea" v-model="result.content" style="width:100%">
                </el-input>
            </el-form-item>
            <el-form-item size="large" id="btn-box">
                <el-button type="primary" @click="onSubmit">完成</el-button>
                <el-button @click="$router.go(-1)">取消</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
import { createNamespacedHelpers } from "vuex";
const { mapState, mapMutations, mapActions } = createNamespacedHelpers(
    "complaints"
);
export default {
    props: ["_id"],
    async mounted() {
        const data = await this.getComplaintsById({ _id: this._id });
        this.nowComplaints = data;
    },
    methods: {
        ...mapActions(["getComplaintsById",'minusLessorsCredits',"handleComplaints","minusTenantsCredits"]),
        onSubmit() {
            if(this.result.state=="投诉对象"){
                this.handleComplaints({_id:this.nowComplaints._id,content:this.result.content})
                this.minusLessorsCredits({_id:this.nowComplaints.cplTarget._id,point:this.result.point})
                this.$router.push("/adminsSystem/adminsComplaints")
            }else{
                this.handleComplaints({_id:this.nowComplaints._id,content:this.result.content})
                this.minusTenantsCredits({_id:this.nowComplaints.name._id,point:this.result.point})
                 this.$router.push("/adminsSystem/adminsComplaints")
            }
        },
    },
    data() {
        return {
            nowComplaints: "",
            result: {
                content:'',
                point:"0",
                state:"投诉对象",
                minusObject:'',
            },
        };
    },
};
</script>

<style>
#btn-box{
    text-align: center;
}
</style>